package com.meixiang.dialog;

import android.os.Bundle;
import android.view.View;

import com.lzy.okhttputils.model.HttpParams;
import com.meixiang.R;
import com.meixiang.activity.account.BindMemberCardActivity;
import com.meixiang.global.Config;
import com.meixiang.http.HttpCallBack;
import com.meixiang.http.HttpUtils;
import com.meixiang.util.AbToastUtil;

import org.json.JSONObject;

import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 会员卡Dialog
 */
public class MemberDialogFragment extends BaseDialogFragment {

    public static String TAG = "MemberDialogFragment";

    public MemberDialogFragment() {
    }

    public static MemberDialogFragment newInstance() {
        return new MemberDialogFragment();
    }

    @Override
    public void onStart() {
        super.onStart();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @Override
    protected int setFragmentViewId() {
        return R.layout.dialog_member_card;
    }


    @Override
    protected void initView(View rootView) {
        ButterKnife.bind(this, rootView);
    }

    @Override
    protected void initData() {

    }

    @OnClick({R.id.tv_change_bind, R.id.tv_cancel_bind, R.id.tv_option})
    public void onClick(View view) {
        Bundle bundle = new Bundle();
        switch (view.getId()) {
            // 添加新会员卡
            case R.id.tv_change_bind:
                dismiss();
                bundle.putInt("key", 1);
                startActivity(BindMemberCardActivity.class, bundle);//  AddMemberCardActivity
                break;
            // 取消绑定
            case R.id.tv_cancel_bind:
                getUnbound();
                dismiss();
                bundle.putInt("key", 2);
                break;
            // 取消
            case R.id.tv_option:
                dismiss();
                break;
        }
    }

    private void getUnbound() {
        HttpParams params = new HttpParams();
        HttpUtils.post(Config.SERVER_URL + "memberCard/api/unbound", params, new HttpCallBack(getActivity()) {
            @Override
            public void onSucceed(JSONObject result, String code, String message) {
                AbToastUtil.showToast(getActivity(), message);
            }

            @Override
            public void onError(String code, String message) {
                AbToastUtil.showToast(getActivity(), message);
            }
        });
    }

}
